﻿using NationalInstruments.DAQmx;
using NPOI.SS.Formula.Functions;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using 低频天线阵列相控阵信号发生系统SmartFASK12.Controls;
using 低频天线阵列相控阵信号发生系统SmartFASK12.Enums;
using 低频天线阵列相控阵信号发生系统SmartFASK12.Models;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using MathNet.Numerics;
using MathNet.Numerics.IntegralTransforms;
using Newtonsoft.Json;
using System.IO;
using MathNet.Numerics.LinearAlgebra.Factorization;
using System.Timers;
using System.Runtime.InteropServices;

namespace 低频天线阵列相控阵信号发生系统SmartFASK12.View
{
    public partial class UDataAcquisition : UserControl
    {
        private System.Windows.Forms.Timer timer;

        /// <summary>
        /// 6218结果
        /// </summary>
        private _6218ResultModel _6218ResultModel;

        /// <summary>
        /// 4431结果
        /// </summary>
        private _4431ResultModel _4431ResultModel;

        private List<Color> _colorList = new List<Color>()
        {
            Color.Red, Color.Green, Color.Blue, Color.Magenta,
        };

        public UDataAcquisition()
        {
            InitializeComponent();

            Init();
        }

        /// <summary>
        /// 初始化
        /// </summary>
        public void Init()
        {
            _6218ResultModel = new _6218ResultModel();
            _4431ResultModel = new _4431ResultModel();

            formsPlotFFT.Plot.Title("FFT");
            formsPlot_RealTime.Plot.Title("实时数据");

            comboBox_PhysicalChannelName1.Items.AddRange(MNI.Singleton().GetChannals(PhysicalChannelTypes.AI));
            if (comboBox_PhysicalChannelName1.Items.Count > 0)
                comboBox_PhysicalChannelName1.SelectedIndex = 0;

            comboBox_PhysicalChannelName2.Items.AddRange(MNI.Singleton().GetChannals(PhysicalChannelTypes.AI));
            if (comboBox_PhysicalChannelName2.Items.Count > 1)
                comboBox_PhysicalChannelName2.SelectedIndex = 1;

            comboBox_PhysicalChannelName3.Items.AddRange(MNI.Singleton().GetChannals(PhysicalChannelTypes.AI));
            if (comboBox_PhysicalChannelName3.Items.Count > 2)
                comboBox_PhysicalChannelName3.SelectedIndex = 2;

            comboBox_PhysicalChannelName4.Items.AddRange(MNI.Singleton().GetChannals(PhysicalChannelTypes.AI));
            if (comboBox_PhysicalChannelName4.Items.Count > 3)
                comboBox_PhysicalChannelName4.SelectedIndex = 3;

            comboBox_CollectionCardType.SelectedIndex = (int)MPublic.ConfigModel.collectionCardType;
            comboBox_Rate.Text = MPublic.ConfigModel.rate2.ToString();
            comboBox_CollectionDuration.Text = MPublic.ConfigModel.collectionDuration4.ToString();
            comboBox_MaximumValue.Text = MPublic.ConfigModel.maximumValue2.ToString();
            comboBox_MinimumValue.Text = MPublic.ConfigModel.minimumValue2.ToString();
            comboBox_PhysicalChannelName1.Text = MPublic.ConfigModel.physicalChannelName_1;
            comboBox_PhysicalChannelName2.Text = MPublic.ConfigModel.physicalChannelName_2;
            comboBox_PhysicalChannelName3.Text = MPublic.ConfigModel.physicalChannelName_3;
            comboBox_PhysicalChannelName4.Text = MPublic.ConfigModel.physicalChannelName_4;
            checkBox_IsStartCollection1.Checked = MPublic.ConfigModel.IsStartCollection1;
            checkBox_IsStartCollection2.Checked = MPublic.ConfigModel.IsStartCollection2;
            checkBox_IsStartCollection3.Checked = MPublic.ConfigModel.IsStartCollection3;
            checkBox_IsStartCollection4.Checked = MPublic.ConfigModel.IsStartCollection4;
        }

        /// <summary>
        /// 采集
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_Start_Click(object sender, EventArgs e)
        {
            //保存Config参数
            SaveConfig();

            //设置剩余设时间
            label_remainder.Text = comboBox_CollectionDuration.Text;

            //采集线程
            Thread thread = new Thread(CollectionThread)
            {
                IsBackground = true,
            };
            thread.Start();

            timer = new System.Windows.Forms.Timer();//创建定时器
            timer.Tick += new EventHandler(timer1_Tick);//事件处理
            timer.Enabled = true;//设置启用定时器
            timer.Interval = 1000;//执行时间
            timer.Start();//开启定时器
        }

        /// <summary> 
        /// 定时器事件处理 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param> 
        private void timer1_Tick(object sender, EventArgs e)
        {
            int remainder = Convert.ToInt32(label_remainder.Text);
            if (remainder > 0)
                label_remainder.Text = (remainder - 1).ToString();
        }

        /// <summary>
        /// 采集线程
        /// </summary>
        private void CollectionThread()
        {
            //采集数量
            int samplesPerChannel = (int)(MPublic.ConfigModel.rate2 * MPublic.ConfigModel.collectionDuration4);
            //间距
            double spacing = MPublic.ConfigModel.collectionDuration4 / samplesPerChannel;

            switch (MPublic.ConfigModel.collectionCardType)
            {
                case CollectionCardTypeEnum.Card_6218:
                    {
                        _6218ResultModel = new _6218ResultModel();

                        //采集数据
                        double[] data = MNI.Singleton().CollectVoltage(MPublic.ConfigModel.physicalChannelName_1,
                                                       MPublic.ConfigModel.minimumValue2,
                                                       MPublic.ConfigModel.maximumValue2,
                                                       MPublic.ConfigModel.rate2,
                                                       samplesPerChannel);

                        timer.Stop();//停止定时器
                        timer.Tick -= new EventHandler(timer1_Tick);//取消事件
                        timer.Enabled = false;//设置禁用定时器

                        //数据
                        if (data == null)
                        {
                            MessageBox.Show("未采集到数据，请检查采集卡参数是否正确，或采集卡是否链接成功!", "提示");
                            return;
                        }

                        double[] windowingData = new double[data.Length];

                        FFTWindowingEnum fFTWindowingEnum = FFTWindowingEnum.None;
                        //加窗
                        Invoke(new Action(() =>
                        {
                            fFTWindowingEnum = (FFTWindowingEnum)comboBox_FFTWindowing.SelectedIndex;
                        }));
                        //加窗
                        switch (fFTWindowingEnum)
                        {
                            case FFTWindowingEnum.None:
                                {
                                    windowingData = data;
                                    break;
                                }
                            case FFTWindowingEnum.HanningWindow:
                                {
                                    // 应用Hanning窗
                                    double[] hanningWindow = MathNet.Numerics.Window.Hann(data.Length);
                                    for (int i = 0; i < data.Length; i++)
                                    {
                                        windowingData[i] = data[i] * hanningWindow[i];
                                    }
                                    break;
                                }
                            case FFTWindowingEnum.HammingWindow:
                                {
                                    // 应用汉明窗
                                    double[] hammingWindow = MathNet.Numerics.Window.Hamming(data.Length);
                                    for (int i = 0; i < data.Length; i++)
                                    {
                                        windowingData[i] = data[i] * hammingWindow[i];
                                    }
                                    break;
                                }
                            case FFTWindowingEnum.BlackmanWindow:
                                {
                                    // 应用Blackman窗口
                                    double[] blackmanWindow = MathNet.Numerics.Window.Blackman(data.Length);
                                    for (int i = 0; i < data.Length; i++)
                                    {
                                        windowingData[i] = data[i] * blackmanWindow[i];
                                    }
                                    break;
                                }
                            case FFTWindowingEnum.Blackman_HarrisWindow:
                                {
                                    // 应用Blackman-Harris窗口
                                    double[] blackmanHarrisWindow = MathNet.Numerics.Window.BlackmanHarris(data.Length);
                                    for (int i = 0; i < data.Length; i++)
                                    {
                                        windowingData[i] = data[i] * blackmanHarrisWindow[i];
                                    }
                                    break;
                                }
                            case FFTWindowingEnum.FlatTop:
                                {
                                    // 应用FlatTop窗口
                                    double[] flatTopWindow = MathNet.Numerics.Window.FlatTop(data.Length);
                                    for (int i = 0; i < data.Length; i++)
                                    {
                                        windowingData[i] = data[i] * flatTopWindow[i];
                                    }
                                    break;
                                }
                            case FFTWindowingEnum.Gauss:
                                {
                                    double sigma = 0;
                                    // 定义窗函数参数
                                    Invoke(new Action(() =>
                                    {
                                        sigma = Convert.ToDouble(comboBox_sigma.Text); // Gauss窗的标准
                                    }));

                                    // 创建窗函数（Gauss窗）
                                    double[] gaussWindow = MathNet.Numerics.Window.Gauss(data.Length, sigma);

                                    // 将输入信号与窗函数进行元素级别的乘法运算
                                    windowingData = data.Select((x, i) => x * gaussWindow[i]).ToArray();
                                    break;
                                }
                        }

                        _6218ResultModel.physicalChannelCount = 1;
                        _6218ResultModel.samplesPerChannel = samplesPerChannel;

                        //数据
                        if (windowingData == null)
                            return;

                        //赋值
                        for (int i = 0; i < windowingData.Length; i++)
                        {
                            _6218ResultModel.xs.Add(spacing * (i + 1));
                            _6218ResultModel.ys.Add(windowingData[i]);
                        }

                        //实时数据
                        BeginInvoke(new Action(() =>
                        {
                            //绘制实时数据
                            formsPlot_RealTime.Plot.Clear();
                            formsPlot_RealTime.Plot.AddSignalXY(_6218ResultModel.xs.ToArray(), _6218ResultModel.ys.ToArray());
                            formsPlot_RealTime.Plot.AxisAuto();
                            formsPlot_RealTime.Refresh();
                        }));

                        //FFT计算
                        MDataModel fftData = MyMatlab.FFT(_6218ResultModel.ys, MPublic.ConfigModel.rate2);
                        _6218ResultModel.fftxs = fftData.XValues;
                        _6218ResultModel.fftys = fftData.YValues;
                        BeginInvoke(new Action(() =>
                        {
                            //绘制FFT
                            formsPlotFFT.Plot.Clear();
                            formsPlotFFT.Plot.AddSignalXY(fftData.XValues.ToArray(), fftData.YValues.ToArray());
                            formsPlotFFT.Plot.AxisAuto();
                            formsPlotFFT.Refresh();
                        }));

                        break;
                    }
                case CollectionCardTypeEnum.Card_4431:
                    {
                        _4431ResultModel = new _4431ResultModel();

                        //采集物理通道数量
                        int physicalChannelCount = 0;
                        //物理通道
                        string physicalChannelName = null;
                        if (MPublic.ConfigModel.IsStartCollection1)
                        {
                            if (physicalChannelName != null)
                                physicalChannelName += ",";
                            physicalChannelName += MPublic.ConfigModel.physicalChannelName_1;
                            physicalChannelCount++;
                        }
                        if (MPublic.ConfigModel.IsStartCollection2)
                        {
                            if (physicalChannelName != null)
                                physicalChannelName += ",";
                            physicalChannelName += MPublic.ConfigModel.physicalChannelName_2;
                            physicalChannelCount++;
                        }
                        if (MPublic.ConfigModel.IsStartCollection3)
                        {
                            if (physicalChannelName != null)
                                physicalChannelName += ",";
                            physicalChannelName += MPublic.ConfigModel.physicalChannelName_3;
                            physicalChannelCount++;
                        }
                        if (MPublic.ConfigModel.IsStartCollection4)
                        {
                            if (physicalChannelName != null)
                                physicalChannelName += ",";
                            physicalChannelName += MPublic.ConfigModel.physicalChannelName_4;
                            physicalChannelCount++;
                        }

                        //采集数据
                        double[,] data = MNI.Singleton().CollectVoltage_4431(physicalChannelName,
                                                       MPublic.ConfigModel.minimumValue2,
                                                       MPublic.ConfigModel.maximumValue2,
                                                       MPublic.ConfigModel.rate2,
                                                       samplesPerChannel,
                                                       AITerminalConfiguration.Pseudodifferential);

                        timer.Stop();//停止定时器
                        timer.Tick -= new EventHandler(timer1_Tick);//取消事件
                        timer.Enabled = false;//设置禁用定时器

                        if (data == null)
                        {
                            MessageBox.Show("未采集到数据，请检查采集卡参数是否正确，或采集卡是否链接成功!","提示");
                            return;
                        }

                        //加窗
                        double[,] windowingData = new double[data.GetLength(0), data.GetLength(1)];
                        for (int k = 0; k < physicalChannelCount; k++)
                        {
                            FFTWindowingEnum fFTWindowingEnum = FFTWindowingEnum.None;
                            //加窗
                            Invoke(new Action(() =>
                            {
                                fFTWindowingEnum = (FFTWindowingEnum)comboBox_FFTWindowing.SelectedIndex;
                            }));
                            switch (fFTWindowingEnum)
                            {
                                case FFTWindowingEnum.None:
                                    {
                                        for (int i = 0; i < data.GetLength(1); i++)
                                        {
                                            windowingData[k,i] = data[k, i];
                                        }
                                        break;
                                    }
                                case FFTWindowingEnum.HanningWindow:
                                    {
                                        // 应用Hanning窗
                                        double[] hanningWindow = MathNet.Numerics.Window.Hann(data.GetLength(1));
                                        for (int i = 0; i < data.GetLength(1); i++)
                                        {
                                            windowingData[k, i] = data[k, i] * hanningWindow[i];
                                        }
                                        break;
                                    }
                                case FFTWindowingEnum.HammingWindow:
                                    {
                                        // 应用汉明窗
                                        double[] hammingWindow = MathNet.Numerics.Window.Hamming(data.GetLength(1));
                                        for (int i = 0; i < data.GetLength(1); i++)
                                        {
                                            windowingData[k, i] = data[k, i] * hammingWindow[i];
                                        }
                                        break;
                                    }
                                case FFTWindowingEnum.BlackmanWindow:
                                    {
                                        // 应用Blackman窗口
                                        double[] blackmanWindow = MathNet.Numerics.Window.Blackman(data.GetLength(1));
                                        for (int i = 0; i < data.GetLength(1); i++)
                                        {
                                            windowingData[k, i] = data[k, i] * blackmanWindow[i];
                                        }
                                        break;
                                    }
                                case FFTWindowingEnum.Blackman_HarrisWindow:
                                    {
                                        // 应用Blackman-Harris窗口
                                        double[] blackmanHarrisWindow = MathNet.Numerics.Window.BlackmanHarris(data.GetLength(1));
                                        for (int i = 0; i < data.GetLength(1); i++)
                                        {
                                            windowingData[k, i] = data[k, i] * blackmanHarrisWindow[i];
                                        }
                                        break;
                                    }
                                case FFTWindowingEnum.FlatTop:
                                    {
                                        // 应用FlatTop窗口
                                        double[] flatTopWindow = MathNet.Numerics.Window.FlatTop(data.GetLength(1));
                                        for (int i = 0; i < data.GetLength(1); i++)
                                        {
                                            windowingData[k, i] = data[k, i] * flatTopWindow[i];
                                        }
                                        break;
                                    }
                                case FFTWindowingEnum.Gauss:
                                    {
                                        double sigma = 0;
                                        // 定义窗函数参数
                                        Invoke(new Action(() =>
                                        {
                                            sigma = Convert.ToDouble(comboBox_sigma.Text); // Gauss窗的标准
                                        }));
                                        // 创建窗函数（Gauss窗）
                                        double[] gaussWindow = MathNet.Numerics.Window.Gauss(data.GetLength(1), sigma);

                                        for (int i = 0; i < data.GetLength(1); i++)
                                        {
                                            windowingData[k, i] = data[k, i] * gaussWindow[i];
                                        }

                                        // 将输入信号与窗函数进行元素级别的乘法运算
                                        //windowingData = windowingData.Select((x, i) => x * gaussWindow[i]).ToArray();
                                        break;
                                    }
                            }
                        }

                        if (windowingData == null)
                            return;

                        _4431ResultModel.physicalChannelCount = physicalChannelCount;
                        _4431ResultModel.samplesPerChannel = samplesPerChannel;
                        //赋值
                        for (int k = 0; k < physicalChannelCount; k++)
                        {
                            for (int i = 0; i < windowingData.GetLength(1); i++)
                            {
                                _4431ResultModel.xs.Add(spacing * (i + 1));
                                _4431ResultModel.ys.Add(windowingData[k, i]);
                            }
                        }

                        //实时数据
                        BeginInvoke(new Action(() =>
                        {
                            //绘制实时数据
                            formsPlot_RealTime.Plot.Clear();
                            //设置图例的可见性
                            formsPlot_RealTime.Plot.Legend();
                            for (int i = 0; i < physicalChannelCount; i++)
                            {
                                formsPlot_RealTime.Plot.AddSignalXY(_4431ResultModel.xs.Skip(i * samplesPerChannel).Take(samplesPerChannel).ToArray(), _4431ResultModel.ys.Skip(i * samplesPerChannel).Take(samplesPerChannel).ToArray(), _colorList[i], "物理通道" + (i + 1));
                            }
                            formsPlot_RealTime.Plot.AxisAuto();
                            formsPlot_RealTime.Refresh();
                        }));

                        //FFT计算
                        for (int i = 0; i < physicalChannelCount; i++)
                        {
                            MDataModel fftData = MyMatlab.FFT(_4431ResultModel.ys.Skip(i * samplesPerChannel).Take(samplesPerChannel).ToList(), MPublic.ConfigModel.rate2);
                            _4431ResultModel.fftxs.AddRange(fftData.XValues);
                            _4431ResultModel.fftys.AddRange(fftData.YValues);
                        }

                        BeginInvoke(new Action(() =>
                        {
                            //绘制FFT
                            formsPlotFFT.Plot.Clear();
                            //设置图例的可见性
                            formsPlotFFT.Plot.Legend();
                            for (int i = 0; i < physicalChannelCount; i++)
                            {
                                formsPlotFFT.Plot.AddSignalXY(_4431ResultModel.fftxs.Skip(i * samplesPerChannel / 2).Take(samplesPerChannel / 2).ToArray(), _4431ResultModel.fftys.Skip(i * samplesPerChannel / 2).Take(samplesPerChannel / 2).ToArray(), _colorList[i], "物理通道" + (i + 1));
                            }
                            formsPlotFFT.Plot.AxisAuto();
                            formsPlotFFT.Refresh();
                        }));

                        break;
                    }
            }
        }

        /// <summary>
        /// 保存
        /// </summary>
        private void SaveConfig()
        {
            MPublic.ConfigModel.collectionCardType = (CollectionCardTypeEnum)comboBox_CollectionCardType.SelectedIndex;
            MPublic.ConfigModel.rate2 = MConvert.Singleton().KToInt(comboBox_Rate.Text);
            MPublic.ConfigModel.collectionDuration4 = Convert.ToDouble(comboBox_CollectionDuration.Text);
            MPublic.ConfigModel.maximumValue2 = Convert.ToDouble(comboBox_MaximumValue.Text);
            MPublic.ConfigModel.minimumValue2 = Convert.ToDouble(comboBox_MinimumValue.Text);
            MPublic.ConfigModel.physicalChannelName_1 = comboBox_PhysicalChannelName1.Text;
            MPublic.ConfigModel.physicalChannelName_2 = comboBox_PhysicalChannelName2.Text;
            MPublic.ConfigModel.physicalChannelName_3 = comboBox_PhysicalChannelName3.Text;
            MPublic.ConfigModel.physicalChannelName_4 = comboBox_PhysicalChannelName4.Text;
            MPublic.ConfigModel.IsStartCollection1 = checkBox_IsStartCollection1.Checked;
            MPublic.ConfigModel.IsStartCollection2 = checkBox_IsStartCollection2.Checked;
            MPublic.ConfigModel.IsStartCollection3 = checkBox_IsStartCollection3.Checked;
            MPublic.ConfigModel.IsStartCollection4 = checkBox_IsStartCollection4.Checked;

            MPublic.ConfigModel = MPublic.ConfigModel;
        }

        /// <summary>
        /// 导出
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_Export_Click(object sender, EventArgs e)
        {
            if (comboBox_CollectionCardType.SelectedIndex == 0)
            {
                if (_4431ResultModel.xs.Count <= 0)
                {
                    MessageBox.Show("当前没有数据可以导出！", "提示");
                    return;
                }
            }
            else if(comboBox_CollectionCardType.SelectedIndex == 1)
            {
                if (_6218ResultModel.xs.Count <= 0)
                {
                    MessageBox.Show("当前没有数据可以导出！", "提示");
                    return;
                }
            }

            //对话框
            SaveFileDialog sfd = new SaveFileDialog();
            //设置保存文件对话框的标题
            sfd.Title = "请选择要保存的文件路径";
            //初始化保存目录，默认exe文件目录
            sfd.InitialDirectory = Application.StartupPath;
            //设置保存文件的类型
            //sfd.Filter = "EXCEL|*.xlsx|EXCEL|*.xls";
            sfd.Filter = "文本文件|*.txt";
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                //获得保存文件的路径
                string filePath = sfd.FileName;
                string json = null;
                //4431
                if (comboBox_CollectionCardType.SelectedIndex == 0)
                {
                    json = JsonConvert.SerializeObject(_4431ResultModel);
                }
                //6218
                else if (comboBox_CollectionCardType.SelectedIndex == 1)
                {
                    json = JsonConvert.SerializeObject(_6218ResultModel);
                }
                File.WriteAllText(filePath, json);
                GC.Collect();
                //if (!MExcel.Singleton().ToExportDataMeasurement(filePath, comboBox_CollectionCardType.SelectedIndex, _6218ResultModel, _4431ResultModel))
                //{
                //    MessageBox.Show("导出数据时发生了异常！", "异常");
                //}
            }
        }

        /// <summary>
        /// 导入数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_Import_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            //openFileDialog.Filter = "Excel Files|*.xlsx";
            openFileDialog.Filter = "文本文件|*.txt";
            openFileDialog.Title = "Select an 文本文件 File";

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                string selectedFilePath = openFileDialog.FileName;
                // 在这里可以使用选中的文件路径进行进一步处理，例如读取文件内容等
                //_4431ResultModel _4431Result = MExcel.Singleton().ReadCollectionInfo(selectedFilePath);
                _4431ResultModel _4431Result = JsonConvert.DeserializeObject<_4431ResultModel>(File.ReadAllText(selectedFilePath));

                if (_4431Result.xs.Count <= 0)
                {
                    MessageBox.Show("导入Excel发送了错误","提示");
                    return;
                }
                //绘制实时数据
                formsPlot_RealTime.Plot.Clear();
                //设置图例的可见性
                formsPlot_RealTime.Plot.Legend();
                for (int i = 0; i < _4431Result.physicalChannelCount; i++)
                {
                    formsPlot_RealTime.Plot.AddSignalXY(_4431Result.xs.Skip(i * _4431Result.samplesPerChannel).Take(_4431Result.samplesPerChannel).ToArray(), _4431Result.ys.Skip(i * _4431Result.samplesPerChannel).Take(_4431Result.samplesPerChannel).ToArray(), _colorList[i], "物理通道" + (i + 1));
                }
                formsPlot_RealTime.Plot.AxisAuto();
                formsPlot_RealTime.Refresh();

                //绘制实时数据
                formsPlotFFT.Plot.Clear();
                //设置图例的可见性
                formsPlotFFT.Plot.Legend();
                for (int i = 0; i < _4431Result.physicalChannelCount; i++)
                {
                    formsPlotFFT.Plot.AddSignalXY(_4431Result.fftxs.Skip(i * _4431Result.samplesPerChannel / 2).Take(_4431Result.samplesPerChannel / 2).ToArray(), _4431Result.fftys.Skip(i * _4431Result.samplesPerChannel / 2).Take(_4431Result.samplesPerChannel / 2).ToArray(), _colorList[i], "物理通道" + (i + 1));
                }
                formsPlotFFT.Plot.AxisAuto();
                formsPlotFFT.Refresh();

                GC.Collect();
            }
        }

        /// <summary>
        /// 选择
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void comboBox_FFTWindowing_SelectedIndexChanged(object sender, EventArgs e)
        {
            if(comboBox_FFTWindowing.SelectedIndex == 6)
            {
                label_sigma.Visible = true;
                comboBox_sigma.Visible = true;
            }
            else
            {
                label_sigma.Visible = false;
                comboBox_sigma.Visible = false;
            }
        }
    }
}
